<?php
    header("Content-Type: text/html; charset=iso-8859-1");
    include "/../includes/session.php";
    include "/../includes/validaUsuario.php";
    require_once "/../includes/DAOs/AdminDAO.php";
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="../css/style.css" rel="stylesheet" type="text/css" />
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
		<script id="jqueryui" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js" defer async></script>
		<script src="//www.google.com/jsapi?key=AIzaSyCZfHRnq7tigC-COeQRmoa9Cxr0vbrK6xw"></script>
		<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
		<script>
			var map;
			var geocoder; // = new google.maps.Geocoder();
			var tempMarker = new google.maps.Marker();
			var locationIcon = new google.maps.MarkerImage(
				"https://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_blue.png",
				new google.maps.Size(12,20),
				new google.maps.Size(6,20)
			);
			var newShadow = new google.maps.MarkerImage(
				"https://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_shadow.png",
				new google.maps.Size(22,20),
				new google.maps.Point(13,13)
			);
			function initialize() {
				geocoder = new google.maps.Geocoder();
				var mapOptions = {
					zoom: 16,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				};
				map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
				// Try HTML5 geolocation
				if(navigator.geolocation) {
					navigator.geolocation.getCurrentPosition(function(position) {
						var pos = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
						map.setCenter(pos);
					}, function() {
						handleNoGeolocation(true);
					});
				} else {
					// Browser doesn't support Geolocation
					handleNoGeolocation(false);
				}
				
				tempMarker.setOptions({
					icon: locationIcon,
					shadow: newShadow,
					draggable: true
				});
				
				google.maps.event.addListener(map, "click", showTempMarker);
				
				function showTempMarker(e) {
					tempMarker.setPosition(e.latLng);
					document.getElementById('lat').value = e.latLng.lat();
					document.getElementById('lon').value = e.latLng.lng();
					google.maps.event.addListener(tempMarker, "drag", function() {
						document.getElementById('lat').value = tempMarker.getPosition().lat();
						document.getElementById('lon').value = tempMarker.getPosition().lng();
					});
					tempMarker.setMap(map);
				}
			}
			
			function handleNoGeolocation(errorFlag) {
				if (errorFlag) {
					var content = 'Error: The Geolocation service failed.';
				} else {
					var content = 'Error: Your browser doesn\'t support geolocation.';
				}
				var options = {
					map: map,
					position: new google.maps.LatLng(-33.034355,-71.596313),
					content: content
				};
				var infowindow = new google.maps.InfoWindow(options);
				map.setCenter(options.position);
			}
			
			function showAddress(address) {
				geocoder.geocode({'address': address}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						var pos = results[0].geometry.location;
						map.setCenter(pos);
						tinyMarker = new google.maps.Marker({
							position: pos,
							map: map,
							icon: locationIcon,
							shadow: newShadow,
							draggable: true
						});
						document.getElementById('lat').value = pos.lat();
						document.getElementById('lon').value = pos.lng();
					} else {
						alert("POKE CHUPA EL PICO");
					}
				});
			}
			
			function buscar(){
				var aux = document.getElementById('address');
				var address = aux.value + ", Chile";
				showAddress(address);
			}
			
			google.maps.event.addDomListener(window, 'load', initialize);
		</script>
        <title>Go Now - Administrador</title>
    </head>
    <body>
        <div class="image" style="width:968px;">		
			  <div class="user">
                <?php
                   $adminDAO = new AdminDAO();
                    $result = $adminDAO->getNombreUsuario($_SESSION['id_user']);
                    list($nombre) = $adminDAO->fetch($result);
                ?>
                <p>Admin: <?php echo $nombre ?> <a href="../includes/logout.php">salir</a></p>
            </div>
			
						<a href="http://localhost/gonow/indexUser.php">
			<img  src="../css/logo.png"  alt="logo"  style="margin-left:35px;"/> </a> 
			</div>
        <div id="contenido2" class="content" style="height:700px;">
		
	    <div id="sidebar">
		  <ul style="height:300px">
		        <li><a href="index.php">Eventos</a></li> 
                <li><a href="usuarios.php">Usuarios</a></li>       
                <li><a href="scripts.php">Scripts</a></li>
                <li style="background:#659C08;"><a href="agregarEvento.php">Agregar Eventos</a></li>
          </ul>				
        </div>
		
				<div style="float:right; width:750px;">
						<div style="float:right; width:420px;">
						 <div style="float: right; margin-right:20px; margin-top:40px; margin-bottom:20px;">
								<table>	
									<tr>
										<td><input type="text" id="address" name="address" value="" /></td>
										<td><input style="width: 100px; margin-top: -1px;" class="green_btn" onClick="buscar();" type="submit" id="Buscar" name="Buscar" value="Buscar"/></td>
									</tr>
								</table>
						</div>	
							<div id="map_canvas" style="  margin-right:20px; height: 450px; width: 400px;"></div>
						</div>
			
					<div class="agregar-box">
						<form action="../includes/controllers/adminController.php?action=agregarEvento" method="post">
						 <p>Nombre del Evento</p>
                        <input type="text" name="nombre" id="nombre" value="" />
						<p>Fecha Inicio (YYYY-MM-dd hh:mm:ss)</p>
                       <input type="text" name="fecha_inicio" id="fecha_inicio" value="" />
						<p>Fecha Termino (YYYY-MM-dd hh:mm:ss)</p>
                        <input type="text" name="fecha_termino" id="fecha_termino" value="" />
						<p>Direccion del Evento</p>
                        <input type="text" name="direccion" id="direccion" value="" />
						<p>Precios</p>
                        <input type="text" name="precios" id="precios" value=""/>
						<p>Categoria</p>
                        <select id="cat" name="cat" >
									<?php
										$adminDAO = new AdminDAO();
										$result = $adminDAO->getCategorias();
										while(list($id,$nombre) = $adminDAO->fetch($result)){
											?>
											<option value="<?php echo $id; ?>"><?php echo $nombre; ?></option>
											<?php
										}
									?>
								</select>
						
						<p>Latitud </p>
                        <input type="text" id="lat" name="lat" size="15" value="" />
						<p>Longitud: </p>
						<input type="text" id="lon" name="lon" size="15" value="" />
						<p>Descripci&oacute;n</p>
						<input type="text" name="descripcion" id="descripcion" value=""/>						
					</div>			
						<input class="green_btn" type="submit" id="agregar" name="agregar"  value="Agregar Evento" style="margin-top:20px; margin-left:120px"/>		
					</form>							
					</div>
        </div>
    </body>
	<footer>		
		<p> Proyecto Seminario II Telem&aacute;tica 2012 &copy Gonz&aacute;lez - Orozco - Pino - Villarreal</p>
    </footer>
</html>

